import { IFeidaoAiNodejsComponent } from '@dfeidao/atom-nodejs/interfaces';
import render from '@dfeidao/atom-nodejs/render/render';
import format from '@dfeidao/atom-web/dt/format';
import set from '@dfeidao/atom-web/global/set';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import p001 from './p001';
import p003 from './p003';
import p005 from './p005';
export default async function na001(fd: IFeidaoAiNodejsComponent) {
	// todo
	// 部门
	const staff_no = "YG00000060";
	const staff_name = "庄开局";
	set("staff_no",staff_no);
	set("staff_name",staff_name);
	const res = await nodejs<{ dt: Array<{ department_no: string }> }>('risk-control/zj-000001/s001', {});
	render(fd.data.node, res, p001, 'p001');
	// 初始化数据
	const res1 = await nodejs<{ dt: Array<{ risk_no: number; risk_content: string; risk_type: string; project_no: string; project_name: string; create_time: number; risk_status: number }>; c: number }>('risk-control/zj-000001/s003', { pn: 1 });
	const ren = res1.dt.map((n) => {
		return { ...n, create_time: format(n.create_time, 2) };
	});
	const arr = res1.dt.map((n) => {
		return (n.project_no);
	});
	const res2 = await nodejs<{ dt: Array<{ equip_depart_name: string; project_manager: string; project_no: string }> }>('risk-control/zj-000001/s005', {
		filter: {
			project_nos: arr
		}
	});
	const arr1 = res2.dt.map((n) => {
		return { equip_depart_name: n.equip_depart_name, project_manager: n.project_manager, project_no: n.project_no };
	});
	const arr2 = Array();
	for (let i = 0; i < ren.length; i++) {
		for (let x = 0; x < arr1.length; x++) {
			if (ren[i].project_no === arr1[x].project_no) {
				arr2[i] = {
					risk_no: ren[i].risk_no,
					risk_content: ren[i].risk_content,
					risk_type: ren[i].risk_type,
					project_name: ren[i].project_name,
					create_time: ren[i].create_time,
					risk_status: ren[i].risk_status,
					project_manager: arr1[x].project_manager,
					equip_depart_name: arr1[x].equip_depart_name
				};
			}
		}
	}
	if (arr2.length > 0) {
		render(fd.data.node, arr2, p003, 'p003');
	}
	if (arr2.length > 20) {
		render(fd.data.node, res1.c, p005, 'p005');
	}
}

